﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessLayer.Tables;

public partial class Admin_FirmaTanitim : ChildPage
{
    Db_Firma firma;
    #region Function
    void KayitBul(string id)
    {
        firma = new Db_Firma();
        if (id != "")
        {
            firma.Frm_Kod = id;
            firma.KayitBul();
            if ((firma.Frm_Kod != "" || firma.Frm_Kod != null))
            {
                txtfrm_kod.Text = firma.Frm_Kod;
                firma.KayitBul();
                txtfrmAdi.Text = firma.Frm_Adi;
                txtAdres.Text = firma.Frm_Adres;
                txtEmail.Text = firma.Frm_Email;
                txtfrmFaaliyet.Text = firma.Frm_Faaliyet;
                txtFax.Text = firma.Frm_Fax;
                txtfrm_kod.Text = firma.Frm_Kod;
                txtSicilNo.Text = firma.Frm_Sicil_No;
                txtTel.Text = firma.Frm_Tel;
                txtfrmVergiAdi.Text = firma.Frm_Vergi_Adi;
                txtVergiNO.Text = firma.Frm_Vergi_No;
                txtWebAdres.Text = firma.Frm_Web;
                txtYetkili.Text = firma.Frm_Yetkili;
                drpfrmYil.SelectedValue = firma.Frm_Yil.ToString();
            }
        }
    }
    private void CreateArea()
    {
        foreach (System.Web.UI.Control c in pnlControls.Controls)
        {
            if (c is CrmControls.CrmTextBox)
            {
                CrmControls.CrmTextBox text = c as CrmControls.CrmTextBox;
                text.Text = "";
            }
            if (c is CrmControls.CrmDropDown)
            {
                CrmControls.CrmDropDown drop = c as CrmControls.CrmDropDown;
                if (drop.SelectedIndex != -1)
                    drop.SelectedValue = "0";
            }
        }
    }
    private void Kaydet()
    {
        firma = new Db_Firma();
        if (txtfrm_kod.Text != "")
        {
            firma.Create_Date = DateTime.Now;
            firma.Create_User = 1;
            firma.Hidden = true;
            firma.Locked = true;
            firma.Update_Date = DateTime.Now;
            firma.Update_User = 1;
            firma.Frm_Adi = txtfrmAdi.Text;
            firma.Frm_Adres = txtAdres.Text;
            firma.Frm_Email = txtEmail.Text;
            firma.Frm_Faaliyet = txtfrmFaaliyet.Text;
            firma.Frm_Fax = txtFax.Text;
            firma.Frm_Kod = txtfrm_kod.Text;
            firma.Frm_Sicil_No = txtSicilNo.Text;
            firma.Frm_Tel = txtTel.Text;
            firma.Frm_Vergi_Adi = txtfrmVergiAdi.Text;
            firma.Frm_Vergi_No = txtVergiNO.Text;
            firma.Frm_Web = txtWebAdres.Text;
            firma.Frm_Yetkili = txtYetkili.Text;
            if (drpfrmYil.SelectedIndex != -1)
                firma.Frm_Yil = int.Parse(drpfrmYil.SelectedItem.Value);
            firma.Save();
            CreateArea();
        }
    }
    private void AttributeAdd()
    {
        imgbtnKaydetKapat.Attributes.Add("onclick", "return Kontrol();");
        imgbtnKaydet.Attributes.Add("onclick", "return Kontrol();");
        imgbtnSil.Attributes.Add("onclick", "return SilKontrol();");
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.Count > 0)
            {
                string id = Request.QueryString["id"].ToString();
                KayitBul(id);
            }
        }
        AttributeAdd();
    }
    protected void imgbtnKaydet_Click(object sender, ImageClickEventArgs e)
    {
        Kaydet();
        this.ClientScript.RegisterStartupScript(typeof(Page), "Yenile", "Refresh();", true);
    }
    protected void imgbtnKaydetKapat_Click(object sender, ImageClickEventArgs e)
    {
        Kaydet();
        this.Page.ClientScript.RegisterStartupScript(typeof(Page), "test", "PageClose();", true);
    }
    protected void imgbtnSil_Click(object sender, ImageClickEventArgs e)
    {
        firma = new Db_Firma();
        if (txtfrm_kod.Text != "")
        {
            firma.Frm_Kod = txtfrm_kod.Text;
            firma.KayitSil();
            CreateArea();
        }
        this.ClientScript.RegisterStartupScript(typeof(Page), "Tazele", "Refresh();", true);
    }
    protected void imgNewREcord_Click(object sender, ImageClickEventArgs e)
    {
        CreateArea();
    }
}
